﻿using System.Web.Security;
using ENail.Domain.Core;
using ENail.Domain.Core.Contract.Services;
using Equation.Enterprise.Framework.Domain.Data;

namespace ENail.ApplicationServices
{
    public class UserMembershipService : IMembershipService
    {
        private readonly MembershipProvider _membershipProvider;
        private readonly IRepository<User> _userRepository;

        public UserMembershipService(IRepository<User> userRepository) : this(null, userRepository)
        {
        }

        public UserMembershipService(MembershipProvider membershipProvider, IRepository<User> userRepository)
        {
            //_membershipProvider = membershipProvider ?? Membership.Provider;
            _membershipProvider = membershipProvider ?? new ENailMembershipProvider(userRepository);
            _userRepository = userRepository;
        }

        public bool ValidateUser(string username, string password)
        {
            return ((ENailMembershipProvider)_membershipProvider).ValidateUser(username, password);
        }

        public User GetUser(string username)
        {
            return ((ENailMembershipProvider)_membershipProvider).GetUser(username);
        }

        public User CreateUser(string username, string password)
        {
            return ((ENailMembershipProvider) _membershipProvider).CreateUser(username, password);
        }
    }

}
